<template>
	<view>
		<Header title="协议列表" :showBack="true"></Header>
		<view class="container">
			<view class="milk-box" v-if="milkList.length>0">
				<view class="milk-list">
					<block v-for="(item,index) in milkList" :key="index">
						<view class="item" @click="goDetails(item.url)">
							<rich-text :nodes="item.title" class="left"></rich-text>
							<image class="let-go" src="../../static/img/go.png"></image>
						</view>
					</block>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				milkList: [
					{title: '用户服务协议', url: '/pages/agreement/agreement'},
					{title: '用户隐私协议', url: ''}
				],
			}
		},
		onShow(e) {
			// if(this.milkList.length==0) this.getMilkList()
			this.getLastReadProtocol()
		},
		methods: {
			getStatus(){
				console.log('我被调用')
				wx.openPrivacyContract({
					success:res=>{
						console.log(res)
					}
				})
			},
			
			getLastReadProtocol(){
				this.$http('/service/api/student/getLastReadProtocol',{},res=>{
					console.log(res)
					if(res.data.data){
						this.milkList[0].title = `${this.milkList[0].title} <span style="font-size: 24rpx;">生效时间:${res.data.data.creationTime.split(' ')[0]}</span>`
					}
				},'GET')
			},
			goDetails(url){
				if(url == '/pages/agreement/agreement'){
					uni.navigateTo({ url })
				}else{
					this.getStatus()
				}
				// uni.navigateTo({
				// 	url: '/pages/privacyList/privacyDetail?id='+ url
				// })
			},
			getMilkList(){
				this.$http('/service/api/milkKnowledge/list',{},res=>{
					if(res.data.succeeded) this.milkList = res.data.data
				})
			},
		}
	}
</script>

<style scoped lang="less">
	.milk-box{
		background: #fff;
		border-radius: 16upx;
		box-shadow: 0 3upx 20upx 1upx rgba(247, 200, 122, .2);
		padding: 20upx;
		.milk-list{
			font-size: 26upx;
			padding-left: 28upx;
			width: 582upx;
			.item{
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 78upx;
				.left{
					width: 526upx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.let-go{
					width: 20upx;
					height: 20upx;
				}
			}
		}
	}
	.fz-24{
		font-size: 24upx;
	}
</style>
